<?php

namespace App\Http\Controllers\Api;

use App\Repositories\Api\ContentRepository;
use App\Repositories\CategoryRepository;

class ContentController extends MiniAppController
{
    private $contentRep = null,
        $categoryRep = null;

    public function __construct(
        ContentRepository  $contentRep,
        CategoryRepository $categoryRep,
    )
    {
        parent::__construct();
        $this->contentRep = $contentRep;
        $this->categoryRep = $categoryRep;
    }

    public function index()
    {
        $params = request()->only("category_id", "limit");

        if (!$params['category_id']) {
            $params['category_id'] = -1;
        }
        $res = $this->contentRep->getPages($params, $this->pageSize, $this->pageNum);
        return retSuc($res);
    }

    public function detail()
    {
        $params = request()->only("id");
        $res = $this->contentRep->getOne($params['id']);

        return $this->apiResponse->success($res);
    }

    /**
     * 分类详情
     * @param null $id
     */
    public function category($id = 0)
    {
        $id = intval($id);
        if (!$id)
            return retFail("分类参数错误");
        $res = $this->categoryRep->getById($id);
        return retSuc($res);
    }

}